﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LPV_POS.mh_pos.mh_inbaocao;

namespace LPV_POS.mh_pos.mh_doanhthu
{
    public partial class frmBaoCao_CongNo_NhaCungCap : Form
    {
        public frmBaoCao_CongNo_NhaCungCap()
        {
            InitializeComponent();
        }

        private void frmBaoCao_CongNo_NhaCungCap_Load(object sender, EventArgs e)
        {
            this.btnTim_Click(null, null);
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            thuvien othuvien = new thuvien();
            DataTable tb = othuvien.SP_SelectDataTable("sp_DM_CONGNO_NHACUNGCAP", new string[] { "@flag", "@ICON_NO" }, new object[] { 4, radioButton1.Checked });
            grdData.DataSource = tb;
            btnChiTiet.Enabled = tb.Rows.Count > 0;
            btnExcel.Enabled = tb.Rows.Count > 0;
        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();
            s.Filter += "*.xls|*.xls";
            s.FileName = "Cong_No_NCC_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls";
            if (s.ShowDialog() == DialogResult.OK)
            {
                string FN = s.FileName;
                grvData.ExportToExcelOld(FN);
                if (System.IO.File.Exists(s.FileName))
                    System.Diagnostics.Process.Start(s.FileName);
            }
        }

        private void btnChiTiet_Click(object sender, EventArgs e)
        {
            DataRow dr = grvData.GetDataRow(grvData.FocusedRowHandle);
            if (dr != null)
            {
                frmBaoCao_CongNo_NhaCungCap_CT frm = new frmBaoCao_CongNo_NhaCungCap_CT(dr["NHACC_MA"] + "", dr["NHACC_TEN"] + "");
                frm.ShowDialog();
            }
        }

    }
}
